#ifndef SCHEDULER_H
#define SCHEDULER_H

#include "process_management.h"
#include "null.h"
#include "types.h"

/* global variables  */

/* type declaration */
typedef struct{
  PCB* queue[NUMBER_MAX_PROCESSES];
  int count;
}ready_queue_t;

int round_robin; /* indicates if the scheduler is in RR mode */
int round_robin_index; /* next process to execute using RR */
PCB* running; /* the current running process */

/* functions declarations */

/* initializes the scheduler's data structures */
void initialize_scheduler();

/* inserts the pointer on the PCB pcb in the ready queue.
   The insertion keeps the queue sorted by priority.
   Returns 0 if the queue is full, 1 otherwise
*/
int32_t insert_ready_queue(PCB* pcb);

/* removes pcb from the ready queue
   Returns 1 if the operation succeeded, 0 otherwise.
*/
int32_t remove_ready_queue(PCB* pcb);

/* returns the first process of the ready queue (or NULL) */
PCB* get_first();

/* returns the process at index n in the ready queue (or NULL) */
PCB* get_by_index(int n);

/* returns running */
PCB* get_running();

/* corrects the values in in_ready_queue after a change_priority */
void do_change_priority(int32_t old, int32_t new);

/* sorts the ready queue by priority */
void sort_ready_queue();

/* chooses the next process to run.
   Returns NULL if there is no the queue is empty.
*/
PCB* choose_next_process();

/* selects the process that is to be run according to our policy */
void schedule();

#endif
